<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="./lib/bootstrap.css">
</head>
<body>
<button id="btnPost">发送POST请求</button>
<button id="btnGet">发送GET请求</button>
<button id="btnGet22">发送GET22请求</button>
<button id="btnPost22">发送POST22请求</button>
<script src="./lib/axios.js"></script>
<script src="./lib/vue-2.6.12.js"></script>
<script>
    document.querySelector("#btnPost").addEventListener('click', async function () {
        /*const res = await axios({
            method: "post",
            url: "http://www.liulongbin.top:3006/api/post",
            params: {    // 请求参数

            },
            data: {      //请求体
                name: 'zs',
                age: 20
            }
        });
        console.log(res);*/
        const {data} = await axios({
            method: "post",
            url: "http://www.liulongbin.top:3006/api/post",
            params: {    // 请求参数

            },
            data: {      //请求体
                name: 'zs',
                age: 20
            }
        });
        console.log(data);
    });

    document.querySelector("#btnGet").addEventListener("click", async function () {
        //解构赋值的时候使用：进行重命名为res
        const {data: res} = await axios({
            method: "get",
            url: "http://www.liulongbin.top:3006/api/getbooks",
        });
        console.log(res.data);
    });

    document.querySelector("#btnGet22").addEventListener("click", async function () {
        //解构赋值的时候使用：进行重命名为res
        const {data: res} = await axios.get("http://www.liulongbin.top:3006/api/getbooks");
        console.log(res.data);
    });

    document.querySelector("#btnPost22").addEventListener('click', async function () {
        const {data: res} = await axios.post("http://www.liulongbin.top:3006/api/post", {
            //请求体
            name: 'zs',
            age: 20
        });
        console.log(res);
    });

</script>
</body>
</html>